package com.baway.router

import android.content.Context
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.annotation.Interceptor
import com.alibaba.android.arouter.facade.callback.InterceptorCallback
import com.alibaba.android.arouter.facade.template.IInterceptor
import com.tencent.mmkv.MMKV


/**
 * Author: Jason Zhang
 * Date: 2025/8/19
 * Desc: 页面路由参数拦截器
 * 场景：页面追踪
 */
@Interceptor(priority = 4, name = "路由参数拦截器")
class RouteParamsInterceptor: IInterceptor {

    private lateinit var mContent: Context

    override fun init(context: Context?) {
        context?.let {
            mContent = it
        }
    }

    override fun process(postcard: Postcard?, callback: InterceptorCallback?) {
        val traceId = MMKV.defaultMMKV().decodeString("traceId", "cmq")
        if (!traceId.isNullOrEmpty()){
            postcard?.withString("traceId", traceId)
        }
        callback?.onContinue(postcard)
    }


}